package cn.ctyun.ipush.web.user.dao;

import cn.ctyun.ipush.web.user.bo.MenuTreeNode;
import com.dexcoder.dal.JdbcDao;
import com.dexcoder.dal.build.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by yanghongbo on 2016/7/11.
 */
@Component
public class MenuDao {
    @Autowired
    private JdbcDao jdbcDao;

    public List<MenuTreeNode> listAll(MenuTreeNode menuTreeNode){

        try{
            Criteria criteria = Criteria.select(MenuTreeNode.class).asc("menuOrder");
            List list = jdbcDao.queryList(menuTreeNode,criteria);

            return  list;
        }catch (Exception e){
            return null;
        }

    }


    public MenuTreeNode querySingleMenu(MenuTreeNode menuTreeNode){

        try{
            MenuTreeNode tmp = jdbcDao.querySingleResult(menuTreeNode);

            return  tmp;
        }catch (Exception e){
            return null;
        }

    }
    public boolean saveMenu(MenuTreeNode menuTreeNode){
        try{
            jdbcDao.save(menuTreeNode);
            return true;
        }catch (Exception e){
            return false;
        }
    }
    public boolean deleteMenu(MenuTreeNode menuTreeNode){
        try{
            jdbcDao.delete(menuTreeNode);
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
